﻿using BLL;
using DAL;
using MODEL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Loginter.登录用户信息
{
    public partial class UserInfoXiangQing : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            #region session传值.用户信息
            ////姓名
            //string userName;
            //userName = Session["Name"].ToString();
            //lab_Name.Text = userName;

            ////性别
            //string userSex;
            //userSex = Session["UserSex"].ToString();
            //int sexs = Convert.ToInt32(userSex);
            //if (sexs == 0)
            //{
            //    lab_Sex.Text = "男";
            //}
            //else
            //{
            //    lab_Sex.Text = "女";
            //}

            ////角色
            //string userRole;
            //userRole = Session["Role"].ToString();
            //lab_Role.Text = userRole;

            ////电话
            //string userPhone;
            //userPhone = Session["UserPhone"].ToString();
            //lab_Phone.Text = userPhone;

            ////邮箱
            //string userEmail;
            //userEmail = Session["UserEmail"].ToString();
            //lab_Email.Text = userEmail;
            #endregion

            #region 离线式.封装传值
            //string StrCon = "Data Source=.;Initial Catalog=master;Integrated Security=True";
            ////声明sql语句,参数化查询
            //string select = "select u.UserID, u.UserName,u.Sex,u.Phone,u.Email,r.RoleName from dbo.[User] as u inner join dbo.Role as r on u.FK_RoleID=r.RoleID where UserID=@UserID";

            ////强制转换，在执行报错的时候直接报错
            ////CurrenUser cure = (CurrenUser)Session["cure"];
            ////as转换类型是在报错的时候执行为null
            //CurrenUser cure = Session["UserInfo"] as CurrenUser;
            //int id = Convert.ToInt32(Session["UserInfo"]);
            //if (id != 0)
            //{
            //    SqlParameter[] pams = {
            //    new SqlParameter("@UserID",id)
            //};
            //    DataTable table = DBhelper.SqlDataAdapter(select, pams);
            //    if (table.Rows.Count > 0)
            //    {
            //        DataRow row = table.Rows[0];
            //        lab_Name.Text = row["UserName"].ToString();
            //        lab_Sex.Text = Convert.ToInt32(row["Sex"]) == 0 ? "男" : "女";
            //        lab_Role.Text = row["RoleName"].ToString();
            //        lab_Phone.Text = row["Phone"].ToString();
            //        lab_Email.Text = row["Email"].ToString();
            //    }
            #endregion

            #region 三层架构原版
            //if (!IsPostBack)
            //{
            //    //定义变量ID，session接收
            //    int id = Convert.ToInt32(Session["ID"]);
            //    //调用BLL层中的GetIDAll并将参数id传递，MODEL层中的CurrenUser赋一个对象
            //    CurrenUser user = UserBLL.GetIDAll(id);

            //    if (user != null)
            //    {
            //        //姓名
            //        lab_Name.Text = user.UserName;
            //        //性别
            //        lab_Sex.Text = user.Sex;
            //        //电话
            //        lab_Phone.Text = user.Phone;
            //        //邮箱
            //        lab_Email.Text = user.Email;
            //        //角色
            //        lab_Role.Text = user.RoleName;
            //    }
            //    else
            //    {
            //        Server.Transfer("Login.aspx");
            //    }
            //}
            #endregion

            #region 三层架构.连线式
           
            UserBLL man = new UserBLL();
            int id = Convert.ToInt32(Session["userInfo"]);
            CurrenUser cur = man.GetUserByID(id);
            //CurrenUser cur = Session["userInfo"] as CurrenUser;
            if (cur != null)
            {
                labl.Text = cur.UserName;
                //姓名
                lab_Name.Text = cur.UserName;
                //性别
                lab_Sex.Text = cur.Sex;
                //电话
                lab_Phone.Text = cur.Phone;
                //邮箱
                lab_Email.Text = cur.Email;
                //角色
                lab_Role.Text = cur.RoleName;
            }
            #endregion
        }
    }
}